package com.taptech.doufu.ui.view;

import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;

import com.taptech.doufu.ui.activity.NovelSectionDetailsActivity;
import com.taptech.doufu.ui.adapter.SectionNovelAdapter;
import com.taptech.doufu.bean.HomeTopBean;
import com.taptech.doufu.constant.Constant;

public class HomeSectionNovelListView extends PullToRefreshListView {
	private SectionNovelAdapter mAdapter;
	public HomeSectionNovelListView(Context context) {
		super(context);
		init(context);
	}

	public HomeSectionNovelListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public HomeSectionNovelListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

	@Override
	public void onDraw(Canvas canvas) {
		super.onDraw(canvas);

	}

	private void init(Context context) {
		// mGestureDetector = new GestureDetector(new YScrollDetector());

		// enable child touch
		/* this.mEnableChildTouchEvent = false; */
		this.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View view,
					final int position, long arg3) {
			   HomeTopBean bean=mAdapter.getBean(position-1);
			   if(bean!=null){
				   mAdapter.setHirstory(bean.getId());
				   mAdapter.notifyDataSetChanged();
				   Intent intent=new Intent(getContext(),NovelSectionDetailsActivity.class);
	               intent.putExtra(Constant.ARTICLE_ID, bean.getId());// details id
	               intent.putExtra(Constant.ARTICLE_NOVELID, mAdapter.getNovelId());//topic id
	               getContext().startActivity(intent); 
	               mAdapter.stopActivity();
			   }
             
			}
		});
	}

	public void setAdapter(SectionNovelAdapter adapter) {
		mAdapter =  adapter;
		super.setAdapter(adapter);
	}



}
